package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcxw.hxzbapi.dao.mapper.IncomeUnionMapper;
import com.lcxw.hxzbapi.entity.pojo.IncomeUnion;
import com.lcxw.hxzbcommon.common.StringUtil;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class IncomeUnionService {

    @Resource
    IncomeUnionMapper incomeUnionMapper;

    public int insert(IncomeUnion incomeUnion) {
        return incomeUnionMapper.insert(incomeUnion);
    }

    public int updateById(IncomeUnion incomeUnion) {
        return incomeUnionMapper.updateById(incomeUnion);
    }

    public IncomeUnion selectById(int id) {
        return incomeUnionMapper.selectById(id);
    }

    public IPage<IncomeUnion> selectList(Integer unionId, String term, String status, int pageNum,
        int pageSize) {
        IPage<IncomeUnion> page = new Page<>(pageNum, pageSize);
        QueryWrapper<IncomeUnion> wrapper = new QueryWrapper<>();
        wrapper.eq(unionId != null, "unionId", unionId);
        wrapper.eq(!StringUtil.isEmpty(term), "term", term);
        wrapper.eq(!StringUtil.isEmpty(status), "status", status);
        return incomeUnionMapper.selectPage(page, wrapper);
    }

    public List<String> selectTerms() {
        return incomeUnionMapper.selectTerms();
    }

}
